home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / wnos / wn941101 / arcnet.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-10  |  2.5 KB  |  127 lines

  1. /* Stuff generic to all ARCnet controllers */
  2. #include "global.h"
  3. #include "config.h"
  4. #ifdef ARCNET
  5. #include "mbuf.h"
  6. #include "iface.h"
  7. #include "timer.h"
  8. #include "arp.h"
  9. #include "ip.h"
  10. #include "arcnet.h"
  11.  
  12. char ARC_bdcst[] = { 0 };
  13.  
  14. /* Convert ARCnet header in host form to network mbuf */
  15. static struct mbuf *
  16. htonarc(struct arc *arc,struct mbuf *data)
  17. {
  18.     struct mbuf *bp;
  19.     char *cp;
  20.  
  21.     if((bp = pushdown(data,ARCLEN)) == NULLBUF)
  22.         return NULLBUF;
  23.  
  24.     cp = bp->data;
  25.  
  26.     memcpy(cp,arc->source,AADDR_LEN);
  27.     cp += AADDR_LEN;
  28.     memcpy(cp,arc->dest,AADDR_LEN);
  29.     cp += AADDR_LEN;
  30.     *cp++ = arc->type;
  31.  
  32.     return bp;
  33. }
  34.  
  35. /* Extract ARCnet header */
  36. int
  37. ntoharc(struct arc *arc,struct mbuf **bpp)
  38. {
  39.     pullup(bpp,arc->source,AADDR_LEN);
  40.     pullup(bpp,arc->dest,AADDR_LEN);
  41.     arc->type = PULLCHAR(bpp);
  42.  
  43.     return ARCLEN;
  44. }
  45.  
  46. /* Format an ARCnet address into a printable ascii string */
  47. char *
  48. parc(char *out,char *addr)
  49. {
  50.     sprintf(out,"%02x",uchar(addr[0]));
  51.     return  out;
  52. }
  53.  
  54. /* Convert an ARCnet address from Hex/ASCII to binary */
  55. int
  56. garc(char *out,char *cp)
  57. {
  58.     *out = htoi(cp);
  59.     return 0;
  60. }
  61.  
  62. /* Send an IP datagram on ARCnet */
  63. int
  64. anet_send(bp,iface,gateway,prec,del,tput,rel)
  65. struct mbuf *bp;    /* Buffer to send */
  66. struct iface *iface;    /* Pointer to interface control block */
  67. int32 gateway;        /* IP address of next hop */
  68. int prec;
  69. int del;
  70. int tput;
  71. int rel;
  72. {
  73.     char *agate = res_arp(iface,ARP_ARCNET,gateway,bp);
  74.  
  75.     if(agate != NULLCHAR)
  76.         return (*iface->output)(iface,agate,iface->hwaddr,ARC_IP,bp);
  77.     return 0;
  78. }
  79.  
  80. /* Send a packet with ARCnet header */
  81. int
  82. anet_output(iface,dest,source,type,data)
  83. struct iface *iface;    /* Pointer to interface control block */
  84. char *dest;        /* Destination ARCnet address */
  85. char *source;        /* Source ARCnet address */
  86. int16 type;        /* Type field */
  87. struct mbuf *data;    /* Data field */
  88. {
  89.     struct arc ap;
  90.     struct mbuf *bp;
  91.  
  92.     memcpy(ap.dest,dest,AADDR_LEN);
  93.     memcpy(ap.source,source,AADDR_LEN);
  94.     ap.type = type;
  95.  
  96.     if((bp = htonarc(&ap,data)) == NULLBUF){
  97.         free_p(data);
  98.         return -1;
  99.     }
  100.     return (*iface->raw)(iface,bp);
  101. }
  102.  
  103. /* Process incoming ARCnet packets. Shared by all ARCnet drivers. */
  104. void
  105. aproc(iface,bp)
  106. struct iface *iface;
  107. struct mbuf *bp;
  108. {
  109.     struct arc hdr;
  110.  
  111.     /* Remove ARCnet header and kick packet upstairs */
  112.     ntoharc(&hdr,&bp);
  113.  
  114.     switch(uchar(hdr.type)){
  115.     case ARC_ARP:
  116.         arp_input(iface,bp);
  117.         break;
  118.     case ARC_IP:
  119.         ip_route(iface,NULLIF,bp,0);
  120.         break;
  121.     default:
  122.         free_p(bp);
  123.         break;
  124.     }
  125. }
  126.  
  127. #endif /* ARCNET */